<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('出资人信息') }}</span>
    </div>
    <el-table v-loading="loading" tooltip-effect="darkTable" :data="bfCapitalList" border>
      <el-table-column :label="$t('出资人属性')" align="center" prop="investorAttr" :formatter="investorAttrFormat" width="110" />
      <el-table-column :label="$t('出资人名称')" align="center" prop="actTitle" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span v-if="scope.row.investorAttr !== 'QT'" class="link-type" @click="updateHandle(scope.row)">{{ scope.row.investmentInvestorName }}</span>
          <span v-else class="link-type" @click="updateHandle(scope.row)">{{ scope.row.investorName }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('出资人类型')" align="center" prop="investorType" :formatter="investorTypeFormat" width="170" />
      <el-table-column :label="$t('认缴时间')" align="center" prop="subscribeTime" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.subscribeTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('认缴金额') + $t('金额单位')" align="center" prop="subscribeAmount" width="140" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.subscribeAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('累计实缴金额') + $t('金额单位')" align="center" prop="totalPaidIn" width="140" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.totalPaidIn, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('操作')"
        align="center"
        class-name="small-padding fixed-width"
        width="200"
      >
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['bf:capital::edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}
          </el-button>
          <el-button
            v-hasPermi="['bf:capital:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改出资人信息对话框 -->
    <el-dialog
      :title="$t('出资人信息')"
      :visible.sync="formOpen"
      :close-on-click-modal="false"
      :lock-scroll="false"
      custom-class="dialogForm"
      append-to-body
    >
      <bfCapitalForm ref="bfCapitalForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listBfCapital, delBfCapital } from '@/api/bf/capital/bfCapital'
import bfCapitalForm from '@/views/bf/capital/bfCapitalForm.vue'

export default {
  components: {
    bfCapitalForm
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 出资人信息表格数据
      bfCapitalList: [],
      // 是否显示弹出层
      formOpen: false,
      // 出资人属性字典
      investorAttrOptions: [],
      investorAttrTypeOptions: [],
      // 出资人类型字典
      investorTypeOptions: [],
      // 是否为投资机构字典
      whetherInvestOrgOptions: [],
      // 查询参数
      queryParams: {
        dealId: this.$route.query.id,
        pageNum: 1,
        pageSize: 5
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
    this.getDicts('bf_investor_attr').then(response => {
      this.investorAttrOptions = response.data
    })
    this.getDicts('deal_investment_type').then(response => {
      this.investorAttrTypeOptions = response.data
    })
    this.getDicts('investor_type').then(response => {
      this.investorTypeOptions = response.data
    })
    this.getDicts('sys_yes_no').then(response => {
      this.whetherInvestOrgOptions = response.data
    })
  },
  methods: {
    /** 查询出资详情列表 */
    getList() {
      this.loading = true
      listBfCapital(this.queryParams).then(response => {
        this.bfCapitalList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 出资人属性字典翻译
    investorAttrFormat(row) {
      if (row.dataSource === 'investment') {
        return this.selectDictLabel(this.investorAttrTypeOptions, row.investorAttr)
      } else {
        return this.selectDictLabel(this.investorAttrOptions, row.investorAttr)
      }
    },
    // 出资人类型字典翻译
    investorTypeFormat(row) {
      return this.selectDictLabel(this.investorTypeOptions, row.investorType)
    },
    // 是否为投资机构字典翻译
    whetherInvestOrgFormat(row) {
      return this.selectDictLabel(this.whetherInvestOrgOptions, row.whetherInvestOrg)
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        dealId: this.$route.query.id,
        investorAttr: undefined,
        investorType: undefined,
        investorName: undefined,
        investmentInvestorName: undefined,
        subscribeTime: undefined,
        subscribeAmount: undefined,
        whetherInvestOrg: '0',
        totalPaidIn: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined,
        remark: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
      this.formOpen = true
      this.$nextTick(() => {
        this.$refs.bfCapitalForm.init(null)
      })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.bfCapitalForm.init(row)
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(function() {
        return delBfCapital(row.id)
      }).then(() => {
        this.getList()
        this.msgSuccess(this.$t('删除成功'))
      }).catch(function() {
      })
    }
  }
}
</script>
